package Controller;


import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import View.PanelAccountView;
import View.PanelDashboard;
import View.PanelHelp;
import View.PanelHolder;
import View.PanelSettings;
import View.PanelMenuBar;
import View.PanelTransactie_MainRekeningen;
import View.PanelTransactie_MainTransacties;
import View.PanelAddTransaction;
import View.PanelAccountDetail;


public class ViewSwitcher implements ActionListener {
	
	private Color defaultButtonColor = new Color(105, 105, 105);
	private Color selectedButtonColor = new Color(95, 95, 95);
	
	public ViewSwitcher() {

	}

	public void actionPerformed(ActionEvent e) {
		
		PanelHolder holder = PanelHolder.getInstance();
		PanelMenuBar menuBar = PanelMenuBar.getInstance();
		
		if(e.getActionCommand().equals("dashboard")){
			holder.remove(holder.getComponentAt(141, 0));
			holder.add(PanelDashboard.getInstance());
			colorSwitch();
			menuBar.getDashboard().setBackground(selectedButtonColor);
			holder.repaint();
			holder.validate();
		}
		if(e.getActionCommand().equals("account")){
			holder.remove(holder.getComponentAt(141, 0));
			holder.add(PanelAccountView.getInstance());
			colorSwitch();
			menuBar.getAccount().setBackground(selectedButtonColor);
			holder.repaint();
			holder.validate();
		}
		if(e.getActionCommand().equals("transaction")){
			holder.remove(holder.getComponentAt(141, 0));
			holder.add(PanelTransactie_MainRekeningen.getInstance());
			colorSwitch();
			menuBar.getTransaction().setBackground(selectedButtonColor);
			holder.repaint();
			holder.validate();
		}
		if(e.getActionCommand().equals("TrgnaarRekeningen")){
			holder.remove(holder.getComponentAt(141, 0));
			holder.add(PanelAccountDetail.getInstance());
			holder.repaint();
			holder.validate();
		}
		if(e.getActionCommand().equals("NewTransaction")){
			holder.remove(holder.getComponentAt(141, 0));
			holder.add(PanelAddTransaction.getInstance());
			holder.repaint();
			holder.validate();
		}
		if(e.getActionCommand().equals("settings")){
			holder.remove(holder.getComponentAt(141, 0));
			holder.add(PanelSettings.getInstance());
			colorSwitch();
			menuBar.getSettings().setBackground(selectedButtonColor);
			holder.repaint();
			holder.validate();
		}
		if(e.getActionCommand().equals("help")){
			holder.remove(holder.getComponentAt(141, 0));
			holder.add(PanelHelp.getInstance());
			colorSwitch();
			menuBar.getHelp().setBackground(selectedButtonColor);
			holder.repaint();
			holder.validate();
		}
	}
	
	private void colorSwitch(){
		
		PanelMenuBar.getInstance().getComponentAt(1, 1).setBackground(defaultButtonColor);
		PanelMenuBar.getInstance().getComponentAt(1, 61).setBackground(defaultButtonColor);
		PanelMenuBar.getInstance().getComponentAt(1, 121).setBackground(defaultButtonColor);
		PanelMenuBar.getInstance().getComponentAt(1, 181).setBackground(defaultButtonColor);
		PanelMenuBar.getInstance().getComponentAt(1, 241).setBackground(defaultButtonColor);
		PanelMenuBar.getInstance().getComponentAt(1, 301).setBackground(defaultButtonColor);
	}

}
